<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.AddressListModule.bean.*,util.*,com.AddressListModule.dao.*"%>  
<%
	//---------分页
	int currentPage=1;
	if(request.getParameter("Page")!=null)
	{
		currentPage=Integer.parseInt(request.getParameter("Page"));
	}
	String phone = session.getAttribute("phone").toString();
	List<KehujifenBean> mmsList = (ArrayList) session.getAttribute("kehujifenList");
	int colSpanNum = 8;
%>
<jsp:include page="../head.jsp"></jsp:include>
<%
	String result = session.getAttribute("resultAdd").toString();
	if(!result.equals("")){
		out.println("<script>alert('"+result+"');</script>");
		session.removeAttribute("resultAdd");
	}
%>
 <body>
  <div id="pager">
  <jsp:include page="../top.jsp"><jsp:param name="topCurrent" value="4" /></jsp:include>
  <jsp:include page="Left.jsp"> <jsp:param name="um" value="14" /></jsp:include> 
		<section id="container">
		 <div id="crumbs">
        	客户管理 &raquo; 客户积分列表
        </div>
		<div id="main">
			<div class="tabs">
				<ul class="tabs-nav clearfix">
					<li>
					 客户积分列表
					</li>
					<li>
					 导入客户积分
					</li>
					<li>
					 新增客户积分
					</li>
				</ul>
				<div class="tabs-panel">
					<table width="100%" class="datalist">
						<thead>
							<tr>
								<th colspan="9" class="tl">
												 
												手机号码：
												<input type="text" name="phone" id="phone" value="<%=phone %>">
												<input type="button" value="查询" onclick="searchContact('../KehujifenServlet?method=searchContact')">&nbsp;&nbsp;
												<input type="button" value="批删" onclick="deleteAllContact('../KehujifenServlet?method=deleteAllContact&phone=<%=phone %>')">
								</th>

							</tr>
							<tr>
								<td width="30" class="tc">
									<input type="checkbox" title="全选"
										onClick="check_allT('deleteAll')"/>
								</td>
								<td>
									手机号码
								</td>
								<td>
									积分
								</td>
								<td>
									最后时间
								</td>
								<td>
									操作
								</td>
							</tr>
						</thead>
						<%
							if (mmsList != null && mmsList.size() > 0) {
								 MyPagination mPage=new MyPagination();
								 mmsList=mPage.getInitPage(mmsList,currentPage,10);
								 AddressModuleDao addressModuleDao = new AddressModuleDao();
								for (KehujifenBean mmsSendBean : mmsList) {
						%>
						<tr>
							<td class="tc">
								<input name="deleteAll" id = "deleteAll" type="checkbox" value="<%=mmsSendBean.getCustomerId() %>"/>
							</td>
							<td><%=mmsSendBean.getCustomerPhone()%></td>
							<td><%=Constant.nullToString(mmsSendBean.getCustomerIntegral())%></td>
							<td><%=Constant.nullToString(mmsSendBean.getLastTime())%></td>
							<td class="tc">
							<a class="duanyu_edit" onclick="$mb=$.msgbox({height:320,width:550,content:{type:'ajax',content:'KehujifenServlet?method=modifyContact&mmsId=<%=mmsSendBean.getCustomerId() %>'},title: '客户积分',onAjaxed: function(data){}});">修改</a>
								<a title="删除" class="duanyu_del"style="cursor:hand" onClick="deleteOneContact('../KehujifenServlet?method=deleteContact&mmsId=<%=mmsSendBean.getCustomerId() %>&phone=<%=phone %>')">删除</a>
							</td>
						</tr>
						<%
							}
								%>
								 <tr>
		     	   					<td colspan="<%=colSpanNum %>"  class="tc" >
		     	   					<%=mPage.printCtrl("KehujifenServlet",currentPage,"&method=lookContact&phone="+phone) %>
		     	   					</td>
	     	                      </tr>
									<%
							}
						%>
					</table>
				</div>
				<div class="tabs-panel">
				    <form id="formimport" name="formimport" enctype="multipart/form-data"  method="post" action="">
                	<table width="100%" class="form">
                	<tr>
                	<th scope="row">导入模版：</th>
                	<td>
                	    <a href="./module/kehujifen.xls" >点击这里下载导入模板</a>
                	</td>
                	</tr>
                      <tr>
                        <th scope="row">导入客户积分：</th>
                        <td>
                           <input  type="file" id="daoru" name="daoru" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="insertImport()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function insertImport(){
                        			var fileName = document.getElementById("daoru").value;
                        			var lastFileName = encodeURI(fileName);
                        			lastFileName = encodeURI(lastFileName);
                        			 var file_Name = fileName.split(".")[fileName.split(".").length-1];
                        			if(file_Name=="xls"||file_Name=="XLS")
                        			{
                        			 
                        			 }else
                        			 {
                        			 	alert("上传文件格式不对，请重新导入！");
                        			 	return ;
                        			 }
                        			formimport.action="./KehujifenServlet?method=importjifenSubmit&realImagePath="+lastFileName;
                        			formimport.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>
				<div class="tabs-panel">
				    <form id="formadd" name="formadd"    method="post" action="">
                	<table width="100%" class="form">
                      <tr>
                        <th scope="row">新增手机号码：</th>
                        <td>
                           <input  type="text" id="addphone" size="16" maxlength="11" name="addphone" value="" />
                        </td>
                        </tr>
                         <tr>
                        <th scope="row">初始化积分：</th>
                        <td>
                           <input  type="text" id="jifen" size="16"  name="jifen" value="0" />
                        </td>
                        </tr>
                        <tr>
                        <th scope="row"></th>
                        <td><input type="button" onclick="addkehujifen()" value=" 提  交 " /></td>
                        	<script type="text/javascript">
                        	//验证上传格式
                        	function addkehujifen(){
                        			var addphone = document.getElementById("addphone").value;
                        			var jifen=document.getElementById("jifen").value;
                        			if(addphone.length==0)
                        			{
                        				alert("手机号码不能为空，请重新添加！");
                        				return;
                        			 } 
                       			    if(jifen.length==0){
                       			    	alert("积分默认初始值为0,不能为空！");
                        				return;
                           			 }
                        			formadd.action="./KehujifenServlet?method=addkehuSubmit";
                        			formadd.submit();
                        		}
                        	</script>
                      </tr>
                        </table>
                        </form>
				</div>

			</div>
		</div>
		</section>
		  <jsp:include page="../foot.jsp"></jsp:include>
		</div>
	</body>
</html>
